cmake_minimum_required(VERSION 3.16)
project(htmlui LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 启用自动UIC, MOC, RCC
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

# 查找Qt包
find_package(Qt6 REQUIRED COMPONENTS Widgets)

# 如果Qt6不可用，尝试Qt5
if(NOT Qt6_FOUND)
    find_package(Qt5 REQUIRED COMPONENTS Widgets)
endif()

# 包含FetchContent模块来获取litehtml
include(FetchContent)
set(LITEHTML_BUILD_TESTING OFF CACHE BOOL "Disable litehtml tests" FORCE)
FetchContent_Declare(
    litehtml
    GIT_REPOSITORY https://github.com/litehtml/litehtml
    GIT_TAG v0.9
)
FetchContent_MakeAvailable(litehtml)

# 设置头文件和源文件
set(HEADERS
    HtmlWidget.h
)

set(SOURCES
    HtmlWidget.cpp
    main.cpp
)

# 创建可执行文件
add_executable(htmlui ${SOURCES} ${HEADERS})

# 链接库
target_link_libraries(htmlui PRIVATE 
    Qt${QT_VERSION_MAJOR}::Widgets
    litehtml
)

# 设置编译选项
target_compile_definitions(htmlui PRIVATE 
    QT_NO_KEYWORDS
    LITEHTML_UTF8
)

# 确保litehtml的包含目录被添加
target_include_directories(htmlui PRIVATE 
    ${litehtml_SOURCE_DIR}/include
)
